<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->increments('id');
            $table->string('order_sn', 32);
            $table->integer('user_id');
            $table->string('order_status', 20)->default('UNCONFIRMED');  // UNCONFIRMED CONFIRMED FINISHED CANCELLED

            $table->tinyInteger('shipping_status')->default(0);                 // 0 未发货 1 已发货 2 全部发货
            $table->string('shipping_code', 32)->nullable();              // 用户选择的配送方式
            $table->string('shipping_name', 32)->nullable();
            // $table->timestamp('confirmed_at')->nullable();                           // 订单确认时间

            $table->tinyInteger('pay_status')->default(0);     // 0 未付款 1 已支付 3 已退款 4 已拒绝退款
            $table->string('pay_code', 32)->nullable();  //ALIPAY, COD(货到付款), COUPON, OTHER, WXPAY
            $table->string('pay_name', 32)->nullable();
            $table->timestamp('paid_at')->nullable();

            $table->string('consignee', 60)->nullable();
            $table->string('province', 32)->nullable();
            $table->string('city', 32)->nullable();
            $table->string('district', 32)->nullable();
            $table->string('address', 255)->nullable();
            $table->string('zip_code', 32)->nullable();
            $table->string('phone', 32)->nullable();

            $table->integer('integral')->default(0);
            $table->decimal('integral_price')->default(0);             // 使用积分抵扣
            $table->decimal('shipping_price')->default(0);             // 邮费
            $table->decimal('balance')->default(0);                    // 使用余额
            $table->decimal('coupon_price')->default(0);               // 优惠券抵扣
            $table->decimal('full_cut_price')->default(0);             // 满减
            $table->decimal('zhuangbi_price')->default(0);
            $table->decimal('qingbi_price')->default(0);
            $table->decimal('promotion_amount')->default(0);           // 促销优惠价
            $table->decimal('discount')->default(0);                   // 价格调整
            $table->decimal('total_amount')->default(0);               // 订单总价
            $table->decimal('order_amount')->default(0);               // 应支付金额

            $table->integer('product_num')->default(0);                // 订单产品数量
            $table->string('promotion_type')->nullable();              // 促销活动类型, 针对订单的促销
            $table->string('promotion_id')->default(0);                // 促销活动id
            $table->string('user_note', 255)->nullable();
            $table->string('admin_note', 255)->nullable();
            $table->integer('parent_id')->default(0);
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
